package app;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import data.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2016/11/4.
 */
public class SampleZuulFilter extends ZuulFilter {
    @Autowired
    private UserRepository userRepository;

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        if (request.getSession().getAttribute("user") == null) {
            ctx.setSendZuulResponse(false);
            ctx.setResponseBody("NOT LOGIN");
            return null;
        }
        return null;
    }
}
